package com.huya.controller.user;

import com.huya.common.result.Result;
import com.huya.pojo.dto.AnswerSubmissionDTO;
import com.huya.pojo.entity.TestRecord;
import com.huya.service.TestRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user/records")
public class TestRecordController {
    @Autowired
    private TestRecordService testRecordService;

    /**
     * 获取用户测试记录
     * @param userId
     * @return
     */
    @GetMapping("/{userId}")
    public Result<List<TestRecord>> getRecordsByUserId(@PathVariable Long userId) {
        return Result.success(testRecordService.getRecordsByUserId(userId));
    }
    /**
     * 开始测试
     * @param userId
     * @param testId
     * @return
     */
    @PostMapping("/start")
    public Result<String> startTest(@RequestParam Long userId, @RequestParam Long testId) {
        return Result.success(testRecordService.startTest(userId, testId));
    }
    /**
     * 提交测试
     * @param answerSubmissionDTO
     * @return
     */
    @PostMapping("/submit")
    public Result<TestRecord> submitTest(@RequestBody AnswerSubmissionDTO answerSubmissionDTO) {
        return Result.success(testRecordService.submitTest(answerSubmissionDTO));
    }
}
